﻿<UserControl x:Class="Shoozla.View.PreviewView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             xmlns:s="clr-namespace:Shoozla"
             xmlns:sv="clr-namespace:Shoozla.ViewModel"
             xmlns:v="clr-namespace:Shoozla.View"             
             d:DesignHeight="500" d:DesignWidth="600"
             x:Name="PreviewViewControl">
    <UserControl.Resources>
        <Style x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type v:CoverView},ResourceId=ImageView}">
        </Style>
        <Style x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type v:CoverView},ResourceId=ImageViewItem}">
        </Style>
        <Style TargetType="{x:Type ListView}" BasedOn="{StaticResource {x:Type ListBox}}">
            <Setter Property="BorderBrush" Value="Black"/>
            <Setter Property="BorderThickness" Value="0.5"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate>
                        <Border Name="bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"
                Background="{TemplateBinding Background}" Margin="{TemplateBinding Margin}">
                            <ScrollViewer Margin="{TemplateBinding Padding}" IsDeferredScrollingEnabled="True">
                               <!--<WrapPanel ItemWidth="100" IsItemsHost="True" MinWidth="102"  Width="{Binding ActualWidth,RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}">
                                </WrapPanel>-->
                                <s:VirtualizingWrapPanel Orientation="Horizontal"  IsItemsHost="True" MinWidth="102"  Width="{Binding ActualWidth,RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}" VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Recycling"></s:VirtualizingWrapPanel>
                            </ScrollViewer>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style TargetType='{x:Type ListViewItem}' BasedOn='{StaticResource {x:Type ListBoxItem}}'>
            <Setter Property="Padding" Value="0"/>
            <Setter Property="Background" Value="#ffffff" />
            <Setter Property="Margin" Value="0"/>
            <Setter Property='HorizontalContentAlignment' Value='Center'/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ListViewItem}">
                        <Border x:Name="Bd" Background="{TemplateBinding Background}" SnapsToDevicePixels="true" BorderThickness="0" BorderBrush="#6FBDE8">
                            <StackPanel>
                                <Image Source="{Binding ImageUrl}" Width="100" Height="100">
                                    <Image.ToolTip>
                                        <TextBlock Text="{Binding FileName}"></TextBlock>
                                    </Image.ToolTip>
                            </Image>
                            <CheckBox HorizontalAlignment="Center" Name="chk1" IsChecked="{Binding Path=IsSelected}"/>
                            </StackPanel>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsSelected"  Value="true">
                                <Setter TargetName="Bd" Property="BorderBrush" Value="#FF143c65" />
                                <Setter Property="Background" TargetName="Bd">
                                    <Setter.Value>
                                        <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                                            <LinearGradientBrush.GradientStops>
                                                <GradientStopCollection>
                                                    <GradientStop Color="#FF75aac7" Offset="0"/>
                                                    <GradientStop Color="#FF143c65" Offset="1"/>
                                                </GradientStopCollection>
                                            </LinearGradientBrush.GradientStops>
                                        </LinearGradientBrush>
                                    </Setter.Value>
                                </Setter>
                            </Trigger>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter TargetName="Bd" Property="Background" Value="#e0eff8" />
                            </Trigger>
                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition Property="IsSelected" Value="true" />
                                    <Condition Property="Selector.IsSelectionActive" Value="True" />
                                </MultiTrigger.Conditions>
                                <Setter Property="Background" TargetName="Bd">
                                    <Setter.Value>
                                        <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                                            <LinearGradientBrush.GradientStops>
                                                <GradientStopCollection>
                                                    <GradientStop Color="#FF75aac7" Offset="0"/>
                                                    <GradientStop Color="#FF143c65" Offset="1"/>
                                                </GradientStopCollection>
                                            </LinearGradientBrush.GradientStops>
                                        </LinearGradientBrush>
                                    </Setter.Value>
                                </Setter>
                                <Setter Property="BorderBrush" TargetName="Bd" Value="#FF143c65"/>
                                <Setter Property="Foreground" Value="White"/>
                            </MultiTrigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>
    <DockPanel Background="{StaticResource BackgroundBrush}" >
        <Grid Background="{StaticResource BackgroundBrush}" DockPanel.Dock="Top">
            <TextBlock Padding="7" Foreground="White">Covers found</TextBlock>
        </Grid>
        <DockPanel DockPanel.Dock="Bottom" VerticalAlignment="Center"  Height="55">
            <Grid DockPanel.Dock="Right" VerticalAlignment="Center" HorizontalAlignment="Right">
                <Button x:Name="applyBT" Command="{Binding Path=CmdApply}" Style="{DynamicResource CmdButton}">
                    <StackPanel  Orientation="Horizontal">
                        <TextBlock VerticalAlignment="Center" Margin="2">Apply</TextBlock>
                        <Image Source="/Shoozla;component/Images/apply.png" Height="44" Width="57"/>
                    </StackPanel>
                </Button>
            </Grid>
            <WrapPanel DockPanel.Dock="Left">
                <Button x:Name="SelectAllBT" Command="{Binding Path=CmdSelectAll}" Width="50" ToolTip="Select All" Style="{DynamicResource CmdButton}" >
                    <Image Source="/Shoozla;component/Images/selectAll.png"/>
                </Button>
                <Button x:Name="SelectNoneBT" Command="{Binding Path=CmdSelectNone}" Width="50" ToolTip="Clear selection" Style="{DynamicResource CmdButton}" >
                    <Image Source="/Shoozla;component/Images/selectNone.png"/>
                </Button>
        </WrapPanel>
        </DockPanel>
        <ListView Name="previewLV" ItemsSource="{Binding Path=CurrentItems}" Background="#DFDFDF">
            <ListView.View>
                <v:CoverView />
            </ListView.View>
       </ListView>      
    </DockPanel>
</UserControl>
